package com.zty.response;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author ZTY
 * @Description 定义通用返回类型
 * @Date 0:21 2023-12-23
 **/

@Data
public final class CommonResponse<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;
    public static <T> CommonResponse<T> success(T data) {
        return CommonResponse.create(data, "success");
    }
    public static <T> CommonResponse<T> createFail(T data) {
        return CommonResponse.create(data, "fail");
    }
    public static <T> CommonResponse<T> success() {
        return CommonResponse.create(null, "success");
    }
    public static <T> CommonResponse<T> fail() {
        return CommonResponse.create(null, "fail");
    }
    public static <T> CommonResponse<T> create(T data, String message) {
        return CommonResponse.create(200, data, message);
    }
    public static <T> CommonResponse<T> create(Integer code, T data, String
            message) {
        CommonResponse<T> commonResponse = new CommonResponse<>();
        commonResponse.setCode(code);
        commonResponse.setMessage(message);
        commonResponse.setData(data);
        return commonResponse;
    }
}
